import { MessageBox,Notification  } from 'element-ui';

const config = {
    install(Vue, options) {
        /**
         * 单键会话窗弹层
         *  success / info / warning / error
         */
        Vue.prototype.$Alert = ({
            title='提示',
            message='',
            confirmButtonText='确定',
            type='info',
            callback
        })=>{
            MessageBox.alert(message,{
                title,
                type,
                confirmButtonText,
                callback: action => {
                    callback && callback(action)
                }
            });
        }

        /**
         * 双键会话窗弹层
         */
        Vue.prototype.$Confirm = ({
              title='提示',
              message='',
              confirmButtonText='确定',
              cancelButtonText='取消',
              success,
              error,
        })=>{
            MessageBox.confirm(message,{
                title,
                confirmButtonText,
                cancelButtonText,
                type:'warning'
            }).then(() => {
                success && success()
            }).catch(() => {
                error && error()
            });
        }

        /**
         * 双击输入会话窗
         */
        Vue.prototype.$Prompt = ({
             title='提示',
             message='',
             confirmButtonText='确定',
             cancelButtonText='取消',
             inputPlaceholder,
             inputValidator,
             inputValue,
             success,
             error,
        })=>{
            MessageBox.prompt(message,{
                title,
                confirmButtonText,
                cancelButtonText,
                inputValidator,
                inputPlaceholder,
                inputValue,
            }).then(data => {
                success && success(data.value)
            }).catch(() => {
                error && error()
            });
        }

        Vue.prototype.$Notify = ({
             type='info',
             title='',
             message='',
             duration=1500,
         })=>{
            Notification({
                type,
                title,
                message,
                duration:duration,
            })
        }

    }
}

export default config
